package cn.edu.sdu.sol.intake_system.repository;

import cn.edu.sdu.sol.intake_system.model.po.Answer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Repository
public interface AnswerRepository extends JpaRepository<Answer, Integer> {

    @Query(value = "from Answer where question.department.departmentId=?1 and person.personInfPk=?2")
    List<Answer> findAnswerListByDepartmentIdAAndPersonId(Integer departmentId, Integer personId);

    @Query(value = "from Answer where person.personInfPk=?1 and question.questionId=?2")
    Optional<Answer> findAnswerByPersonIdAAndQuestionId(Integer personId, Integer questionId);

    @Query(value = "from Answer where question.questionId=?1")
    List<Answer> findByQuestionQuestionId(Integer questionId);
}
